@extends('owner.base')

@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="name" placeholder="请输入姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="phone" id="phone" placeholder="请输入手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="car_no" id="car_no" placeholder="请输入车牌号" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="card_no" id="card_no" placeholder="请输入身份证号" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="search-form">搜 索</button>
                </div>
                <div class="layui-inline" style="float:right">
                    <a type="button" class="layui-btn layui-btn-radius layui-btn-normal" href="/exceldemo/driver.xlsx">
                        下载模板
                    </a>
                    <button type="button" class="layui-btn layui-btn-radius layui-btn-normal" id="test1">
                        导入通讯录
                    </button>

                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>

            {{--<script type="text/html" id="options">--}}
            {{--<div class="layui-btn-group">--}}
            {{--@can('member.member.create')--}}
            {{--<a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>--}}
            {{--@endcan--}}
            {{--@can('member.member.destroy')--}}
            {{--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">禁用</a>--}}
            {{--@endcan--}}
            {{--</div>--}}
            {{--</script>--}}
            <script type="text/html" id="status">
                <input disabled type="checkbox" lay-skin="switch" lay-text="启用|禁用" @{{ d.status==1?'checked':'' }}>
            </script>
        </div>
    </div>
@endsection
@section('script')

    <script>
        layui.use(['layer', 'table', 'form', 'upload'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var upload = layui.upload;
            var loading = '';
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                , height: 500
                , url: "{{ route('owner.driver.data') }}" //数据接口
                , page: true //开启分页
                , cols: [[ //表头

                    {field: 'id', title: 'ID', sort: true}
                    , {field: 'name', title: '姓名',}
                    , {field: 'phone', title: '手机'}
                    , {field: 'car_no', title: '车牌号'}
                    , {field: 'card_no', title: '身份证号',}
                    , {
                        field: 'status', title: '司机状态', templet: function (e) {
                            if (e.status == 0) {
                                return '删除';
                            } else {
                                return '正常';
                            }

                        }
                    }
                    , {field: 'created_at', title: '注册时间',}
                    , {
                        field: '', title: '操作', templet: function (e) {
                            return '<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del" lay-event="del"  >删除</a>';

                        }
                    }

                ]]
            });

            //监听工具条
            table.on('tool(dataTable)', function (obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'del') {
                    $.post('{{route('owner.driver.del')}}', {'id': data.id, 'status': 0}, function (msgjson) {
                        layer.msg(msgjson.msg, {'icon': 5})

                    }, 'json')
                }
            });

            //搜索
            form.on('submit(search-form)', function (data) {
                var fields = data.field;
                dataTable.reload({
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: fields // 搜索字段
                });
                return false;
            });
            //导入
            var uploadInst = upload.render({
                elem: '#test1',//绑定元素
                accept: 'file'
                , url: '{{route('owner.driver.importdriver')}}' //上传接口
                , choose: function (obj) {
                    //弹出加载框
                    loading = layer.load(0, {
                        shade: false,

                    });
                }
                , done: function (res) {

                    //上传完毕回调
                    if (res.code == 0) {
                        layer.close(loading);
                        layer.msg(res.msg, {icon: 6});
                        setTimeout(function () {
                            window.location.href = '{{route('owner.driver')}}';
                        }, 500);
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }


                }
                , error: function () {
                    //请求异常回调
                }
            });
        })


    </script>

@endsection




